<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    手机号：<input type="text" id="mobile"/></br>
    验证码：<input type="password" id="pwd"/>
    <button onclick="login()">登陆</button>
    <button onclick="getMsg()">获取短信验证码</button>

</body>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/encrypt.js"></script>
<script src="js/jsencrypt.min.js"></script>
<script src="js/crypto-js.min.js"></script>
<script>
    function login() {
        var mobile = $('#mobile').val();
        var pwd = $('#pwd').val();
        var aesKey = randomWord(true,16,16);
        var enaesKey = RSAEncrypt(aesKey);

        mobile = Encrypt(mobile,aesKey);
        pwd = Encrypt(pwd,aesKey);
        var data = {'mobile':mobile,'pwd':pwd};
        console.log(JSON.stringify(data));
        var endata = RSAEncrypt(JSON.stringify(data));
        $.ajax({
            url: 'user/login',
            type: 'post',
            data: {'data':endata,'key':enaesKey},
            success: function (res) {
                console.log(res);
                if(res.code == 0){
                    console.log(res.data);
                    localStorage.setItem('token',res.data);
                }
            },
            error: function (res) {
                console.log(res);
            }
        });

    }

    function getMsg() {
        var mobile = $('#mobile').val();
        var aesKey = randomWord(true,16,16);
        var enaesKey = RSAEncrypt(aesKey);

        mobile = Encrypt(mobile,aesKey);
        var data = {'mobile':mobile};
        console.log(JSON.stringify(data));
        var endata = RSAEncrypt(JSON.stringify(data));
        $.ajax({
            url: 'user/getMsg',
            type: 'post',
            data: {'data':endata,'key':enaesKey},
            success: function (res) {
                console.log(res);
                if(res.code == 0){
                    console.log(res.data);
                }
            },
            error: function (res) {
                console.log(res);
            }
        });
    }
</script>
</html>